class CommentController < ApplicationController
  before_filter :login_required, :only=>[:destroy]
  def comment
    @commentable_type = params[:comment][:commentable_type]
    
    @asset = eval("#{@commentable_type}.find(params[:id])")
    comment = Comment.new(params[:comment])
    comment.user_id = session[:user]
    @asset.comments << comment

    @asset = eval("#{@commentable_type}.find(params[:id])")
  end
  
  def destroy
    @comment = Comment.find(params[:id])
    return if @comment.user.id!=session[:user]
    @comment.destroy if session[:user] == @comment.user_id
    redirect_to :back
  end
  
  def comment_photo
    @id = params[:id]
    @div = params[:div]
    @repo = params[:repo]
    
#    @asset = Magazine.find(params[:id])
    render :partial => "comment/comment_photo", :locals => {:id => @id, :div => @div, :repo => @repo}
  end
  
  def update_comment
    @id = params[:id]
    @div = params[:div]
    @repo = params[:repo]
#    puts @repo
    
    @asset = eval("#{@repo}.find(params[:id])")
    
    comment = Comment.new(params[:comment])
    comment.user_id = session[:user]
    @asset.comments << comment

    @asset = eval("#{@repo}.find(params[:id])")
  end
end
